This Jupyter notebook is intented to be used alongside the book Python for Bioinformatics
Note: Before opening the file, this file should be accesible from this Jupyter notebook. In order to do so, the following commands will download these files from Github and extract them into a directory called samples.
In [0]:
!pip install biopython
In [7]:
!curl https://raw.githubusercontent.com/Serulab/Py4Bio/master/samples/samples.tar.bz2 -o samples.tar.bz2
!mkdir samples
!tar xvfj samples.tar.bz2 -C samples
Listing 18.1: fromtxt.py: Primer Tm calculation
In [8]:
from Bio.SeqUtils import MeltingTemp as MT
PRIMER_FILE = 'samples/primers.txt'
for line in open(PRIMER_FILE):
# prm stores the primer, without 5'- and -3'
prm = line[3:len(line)-4].replace(' ','')
# .2f is used to print up to 2 decimals.
print('{0},{1:.2f}'.format(prm, MT.Tm_staluc(prm)))
Listing 18.2: toexcel.py: Primer Tm calculation, Excel output
In [0]:
from Bio.SeqUtils import MeltingTemp as MT
import xlwt
PRIMER_FILE = 'samples/primers.txt'
# w is the name of a newly created workbook.
w = xlwt.Workbook()
# ws is the name of a new sheet in this workbook.
ws = w.add_sheet('Result')
# These two lines writes the titles of the columns.
ws.write(0, 0, 'Primer Sequence')
ws.write(0, 1, 'Tm')
for index, line in enumerate(open(PRIMER_FILE)):
# For each line in the input file, write the primer
# sequence and the Tm
prm = line[3:len(line)-4].replace(' ','')
ws.write(index+1, 0, prm)
ws.write(index+1, 1, '{0:.2f}'.format(MT.Tm_staluc(prm)))
# Save the spreadsheel into a file.
w.save('primerout.xls')
In [0]: